package com.fang.mmy.items.filter;

import com.fang.mmy.entity.User;
import com.fang.mmy.items.constants.Constants;
import com.fang.mmy.items.entity.Item;
import com.fang.mmy.items.entity.ItemRuleDetail;
import com.fang.mmy.items.mapper.ItemRuleDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName AccountFilter
 * @Author kebukeyi
 * @Date 2022/8/9 18:42
 * @Description
 * @Version 1.0.0
 */
@Component
public class AccountFilter extends BaseLogic implements LogicFilter {

    @Autowired
    private ItemRuleDetailMapper itemRuleDetailMapper;

    @Override
    public boolean filter(User user, Item item) {
        String userId = user.getBid();
        List<ItemRuleDetail> allAccountRuleByItemId = itemRuleDetailMapper.getAllAccountRuleByItemId(item.getId(), Constants.ItemRuleCode.Account, Constants.ItemRuleDesc.Account);
        for (ItemRuleDetail detail : allAccountRuleByItemId) {
            boolean logic = decisionLogic(userId, detail);
            if (logic) return true;
        }
        return false;
    }
}
